﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;
using System.Web.Services;
using System.Web.SessionState;

namespace eTruck.Views.Commons
{
    /// <summary>
    /// Summary description for ModuleHandler
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class ModuleHandler : IHttpHandler, IRequiresSessionState
    {

         public void ProcessRequest(HttpContext context)
        {
            try
            {
                string prefixText = context.Request.QueryString["q"];
                BLL.Modules bll = new BLL.Modules();
                DataSet ds = bll.GetModuleByModuleName(prefixText);
                StringBuilder sb = new StringBuilder();
                if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                {
                    foreach(DataRow dr in ds.Tables[0].Rows)
                    {
                        sb.Append(dr["ModuleID"] + "|" + dr["ModuleName"])
                        .Append(Environment.NewLine);
                    }
                }
                context.Response.Write(sb.ToString());

            }
            catch
            {
                context.Response.Write("");
            }
            
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}